#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+100;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL sum[maxn],a[maxn],dp[maxn];
deque<LL>que;
inline LL g(LL i){
    return dp[i-1]-sum[i];
}
int main(void){
   	cin.tie(0);std::ios::sync_with_stdio(false);
    LL n,m;cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
        sum[i]=sum[i-1]+a[i];
    }
    LL ans=0;
    que.push_back(0);
    for(LL i=1;i<=n;i++){
        while(!que.empty()&&i-que.front()>m) que.pop_front();
        while(!que.empty()&&g(que.back())<=g(i)) que.pop_back();
        que.push_back(i);
        dp[i]=max(dp[i],sum[i]+g(que.front()));
        ans=max(ans,dp[i]);
    }
    cout<<ans<<endl;
   	return 0;
}
